<?php

/**
 * This is the model class for table "tbl_client".
 *
 * The followings are the available columns in table 'tbl_client':
 * @property string $id
 * @property string $firstname
 * @property string $lastname
 * @property string $address
 * @property string $city
 * @property string $state
 * @property string $phone
 * @property string $mphone
 * @property string $joined
 * @property string $username
 * @property string $password
 * @property integer $login_type
 * @property string $email
 * @property string $device_mac
 *
 * The followings are the available model relations:
 * @property TblInstallations[] $tblInstallations
 * @property TblMessages[] $tblMessages
 * @property TblSubscriptionLog[] $tblSubscriptionLogs
 */
class Client extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Client the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'tbl_client';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('username', 'required'),
			array('login_type', 'numerical', 'integerOnly'=>true),
			array('firstname, lastname, address, city, state, phone, mphone, email', 'length', 'max'=>45),
			array('username, password, device_mac', 'length', 'max'=>30),
			array('joined', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, firstname, lastname, address, city, state, phone, mphone, joined, username, password, login_type, email, device_mac', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'tblInstallations' => array(self::HAS_MANY, 'TblInstallations', 'tbl_client_id'),
			'tblMessages' => array(self::HAS_MANY, 'TblMessages', 'tbl_client_id'),
			'tblSubscriptionLogs' => array(self::HAS_MANY, 'TblSubscriptionLog', 'tbl_client_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'firstname' => 'Firstname',
			'lastname' => 'Lastname',
			'address' => 'Address',
			'city' => 'City',
			'state' => 'State',
			'phone' => 'Phone',
			'mphone' => 'Mphone',
			'joined' => 'Joined',
			'username' => 'Username',
			'password' => 'Password',
			'login_type' => 'Login Type',
			'email' => 'Email',
			'device_mac' => 'Device Mac',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('firstname',$this->firstname,true);
		$criteria->compare('lastname',$this->lastname,true);
		$criteria->compare('address',$this->address,true);
		$criteria->compare('city',$this->city,true);
		$criteria->compare('state',$this->state,true);
		$criteria->compare('phone',$this->phone,true);
		$criteria->compare('mphone',$this->mphone,true);
		$criteria->compare('joined',$this->joined,true);
		$criteria->compare('username',$this->username,true);
		$criteria->compare('password',$this->password,true);
		$criteria->compare('login_type',$this->login_type);
		$criteria->compare('email',$this->email,true);
		$criteria->compare('device_mac',$this->device_mac,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}